#!/bin/bash

function check_input {
    re='^[0-9]+([.][0-9]+)?$'
    if ! [[ $1 =~ $re ]] ; then
        echo "Error: Input must be a number" >&2
        exit 1
    fi
}

function main {
    sum=0
    while true; do
        read -p "Please enter a number (end to finish): " input
        if [ "$input" == "end" ]; then
            break
        fi
        check_input $input
        sum=$(echo "$sum + $input" | bc)
    done
    printf "The sum is %.2f\n" $sum
}

main